<?php

namespace slinks\extensions\onecms;

use slinks\core\Config\Resource\DirectoryResource;
use slinks\common\Finder\Finder;
use slinks\core\dependencyInjectionExt\annotation\ServiceDefiningAnnotationVisitor;
use slinks\common\io\AnnotationReader;
use slinks\core\DependencyInjection\Loader\XmlFileLoader;
use slinks\core\DependencyInjection\ContainerBuilder;
use slinks\core\dependencyInjectionExt\extension\Extension;

/**
 * Main extension for all 1 CMS functionality
 * 
 * @author Navid Mitchell
 *
 */
class OneCmsExtension extends Extension {

    public function configLoad($config, ContainerBuilder $container) {
        if (!$container->hasDefinition('oneCms')) {

            $path1 = __DIR__.DIRECTORY_SEPARATOR.'cms';
            $path2 = __DIR__.DIRECTORY_SEPARATOR.'core';

            $container->addResource(new DirectoryResource($path1));
            $container->addResource(new DirectoryResource($path2));

            $reader = new AnnotationReader(new ServiceDefiningAnnotationVisitor($container));

            $finder = new Finder();

            $reader->read($finder->files()->name('*.php')->in(array($path1,$path2)));
        }
    }

    /**
     * Returns the base path for the XSD files.
     *
     * @return string The XSD base path
     */
    public function getXsdValidationBasePath() {
        return __DIR__ . '/resources/schema';
    }

    /**
     * Returns the namespace to be used for this extension (XML namespace).
     *
     * @return string The XML namespace
     */
    public function getNamespace() {
        return 'http://www.mitchellsoftware.net/schema/dic/onecms';
    }

    /**
     * Returns the recommended alias to use in XML.
     *
     * This alias is also the mandatory prefix to use when using YAML.
     *
     * @return string The alias
     */
    public function getAlias() {
        return 'onecms';
    }

}